package me.fangsong.timefold.line.exec;


import ai.timefold.solver.core.api.solver.Solver;
import ai.timefold.solver.core.api.solver.SolverFactory;
import ai.timefold.solver.core.config.solver.SolverConfig;
import me.fangsong.timefold.line.constraint.PlanConstraintProvider;
import me.fangsong.timefold.line.domain.Line;
import me.fangsong.timefold.line.domain.Work;
import me.fangsong.timefold.line.solution.Plan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.time.Duration;
import java.time.LocalTime;
import java.util.*;
public class PlanExec {

    private static final Logger LOGGER = LoggerFactory.getLogger(PlanExec.class);

    public static void main(String[] args) {
        SolverFactory<Plan> solverFactory = SolverFactory.create(new SolverConfig()
                .withSolutionClass(Plan.class)
                .withEntityClasses(Line.class,Work.class)
                .withConstraintProviderClass(PlanConstraintProvider.class)
                // The solver runs only for 5 seconds on this small dataset.
                // It's recommended to run for at least 5 minutes ("5m") otherwise.
                .withTerminationSpentLimit(Duration.ofSeconds(5)));

        // Load the problem
        Plan problem = generateDemoData();

        // Solve the problem
        Solver<Plan> solver = solverFactory.buildSolver();
        Plan solution = solver.solve(problem);
        // Visualize the solution
        printTimetable(solution);
    }

    public static Plan generateDemoData() {
        Plan plan = new Plan();

        List<Line> lineList = new ArrayList<>();
        lineList.add(new Line(1,"产线1", LocalTime.of(8, 00, 00),LocalTime.of(12, 00, 00),LocalTime.of(13, 00, 00),LocalTime.of(19, 00, 00)));
        lineList.add(new Line(2,"产线2",LocalTime.of(8, 00, 00),LocalTime.of(12, 00, 00),LocalTime.of(13, 00, 00),LocalTime.of(19, 00, 00)));
        lineList.add(new Line(3,"产线3",LocalTime.of(8, 00, 00),LocalTime.of(12, 00, 00),LocalTime.of(13, 00, 00),LocalTime.of(19, 00, 00)));

        plan.setLineList(lineList);


        List<Work> workList = new ArrayList<>();
        workList.add(new Work(1,"work1",470));
        workList.add(new Work(2,"work2",210));
        workList.add(new Work(3,"work3",290));
        workList.add(new Work(4,"work4",200));
        plan.setWorkList(workList);

        return plan;
    }

    private static void printTimetable(Plan timetable) {
        LOGGER.info("");

    }

}